package com.onpositive.mediawiki.deserializing;

import java.util.Collection;

import storage.v1.WikiStorageProperty;

import com.onpositive.knowledge.model.IThing;
import com.onpositive.knowledge.model.IUniverse;
import com.onpositive.mediawiki.dataminer.MediaWikiUniverse;
import com.onpositive.mediawiki.dataminer.WikiThing;
import com.onpositive.mediawiki.propertyparser.PropertyCharacteristic;
import com.onpositive.semantic.model.api.property.IProperty;
import com.onpositive.semantic.model.api.realm.IRealm;
import com.onpositive.semantic.model.api.realm.Realm;

public class SerializedUniverse extends SerializedStorage implements IUniverse {
	
	IRealm<IThing> realm;
	private Realm<Object> prealm;

	public SerializedUniverse(String binaryPath) {
		super(binaryPath);
	}

	@Override
	public IRealm<IThing> all() {
		if (realm == null)
			realm = super.getRealm(null, null, null);

		return realm;
	}

	@Override
	public IRealm<? extends IProperty> allProperties() {
		if (prealm == null) {
			Iterable<IProperty> properties = getProperties(null);
			Realm<Object> realm = new Realm<Object>();
			for (IProperty m : properties) {
				realm.add(m);
			}
			this.prealm = realm;
		}
		return (IRealm<? extends IProperty>) prealm;
	}
	
	@Override
	protected IThing createThing(Object name ) {
		if( !(name instanceof String) )
			return null ;
		
		return new StoredThing( (String)name, this );
	}


	@Override
	protected void addSpecialProperties(Collection<IProperty> col) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected IProperty getSpecialProperty(String propertyName) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected IProperty createProperty(PropertyCharacteristic pChar) {

		return new WikiStorageProperty( pChar, this ) ;
	}

	@Override
	public boolean save() {
		return true;
	}



}
